//
//  BKEXVoucherDetailCell.m
//  bestkeep
//
//  Created by TOPTEAM on 2017/3/23.
//  Copyright © 2017年 utouu. All rights reserved.
//

#import "BKEXVoucherDetailCell.h"
#import "BKMainCommon.h"
#import "BK_OD_Color.h"








@interface BKEXVoucherDetailCell()

@property(nonatomic,strong)UILabel *voucherType;
@property(nonatomic,strong)UILabel *needScore;
@property(nonatomic,strong)UILabel *warnMsg;
@property(nonatomic,strong)UILabel *explain;
@property(nonatomic,strong)UILabel *voucherExplain;
@end
@implementation BKEXVoucherDetailCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initUI];
    }
    return self;
}

-(void)initUI{
    _voucherType = [UILabel new];
    _voucherType.textColor = RGB(64, 64, 64);
    _voucherType.font = [UIFont systemFontOfSize:15];
    [self addSubview:_voucherType];
    [_voucherType mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset(15);
        make.left.equalTo(self.mas_left).offset(ApplicationBackGauge);
        make.right.equalTo(self.mas_right);
        make.height.equalTo(@20);
    }];
    
    _needScore = [UILabel new];
    _needScore.textColor = RGB(64, 64, 64);
    _needScore.font = [UIFont boldSystemFontOfSize:36];
    [self addSubview:_needScore];
    
    [_needScore mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_voucherType.mas_bottom).offset(15);
        make.left.equalTo(self.mas_left).offset(ApplicationBackGauge);
        make.right.equalTo(self.mas_right);
        make.height.equalTo(@40);
    }];
    
    _warnMsg = [UILabel new];
    _warnMsg.text = @"(每天只能兑换一张)";
    _warnMsg.textColor = kOrderLightGrey1;
    _warnMsg.font = [UIFont systemFontOfSize:15];
    [self addSubview:_warnMsg];
    [_warnMsg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_needScore.mas_bottom).offset(15);
        make.left.equalTo(self.mas_left).offset(ApplicationBackGauge);
        make.right.equalTo(self.mas_right);
        make.height.equalTo(@20);
    }];
    
    UIView *lineView = [UIView new];
    lineView.backgroundColor = kOrderLineGrey2;
    [self addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_warnMsg.mas_bottom).offset(15);
        make.left.equalTo(self.mas_left);
        make.right.equalTo(self.mas_right);
        make.height.equalTo(@0.5);
    }];
    
    _explain = [UILabel new];
    _explain.font = [UIFont boldSystemFontOfSize:18];
    _explain.text = @"优惠券说明：";
    _explain.textColor = kOrderBlack1;
    [self addSubview:_explain];
    [_explain mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lineView.mas_bottom).offset(15);
        make.left.equalTo(self.mas_left).offset(ApplicationBackGauge);
        make.right.equalTo(self.mas_right).offset(-10);
    }];
    
    _voucherExplain = [UILabel new];
    _voucherExplain.font = [UIFont systemFontOfSize:15];
    _voucherExplain.numberOfLines = 0;
    [self addSubview:_voucherExplain];
    
    [_voucherExplain mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_explain.mas_bottom).offset(15);
        make.left.equalTo(self.mas_left).offset(ApplicationBackGauge);
        make.right.equalTo(self.mas_right).offset(-10);
    }];
    
    
}

-(void)setdataWithModel:(BKCouponInfoModel*)model{
    
    self.voucherType.text  = model.rangeandaomunt;
    self.needScore.text = model.exchange_integral;
    NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc]init];
    paragraph.lineSpacing = 10;
    NSString *str = model.explain;
    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:15],NSParagraphStyleAttributeName:paragraph};
    if (str != nil) {
        NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc]initWithString:str attributes:dic];
        [attrStr addAttribute:NSForegroundColorAttributeName value:RGB(64, 64, 64) range:NSMakeRange(0, attrStr.length)];
        [attrStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:15] range:NSMakeRange(0, attrStr.length)];
        _voucherExplain.attributedText = attrStr;
    }
    
    
}

+(CGFloat)getCellHeightWithModel:(BKCouponInfoModel *)model{
    
    NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc]init];
    paragraph.lineSpacing = 10;
    NSString *str = model.explain;
    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:15],NSParagraphStyleAttributeName:paragraph};
    if (str != nil) {
        NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc]initWithString:str attributes:dic];
        [attrStr addAttribute:NSForegroundColorAttributeName value:RGB(64, 64, 64) range:NSMakeRange(0, attrStr.length)];
        [attrStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:15] range:NSMakeRange(0, attrStr.length)];
        
    }
    
    CGSize textSize = [str boundingRectWithSize:CGSizeMake([UIScreen mainScreen].bounds.size.width - 40, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil].size;
    if (iPhone4s  || iPhone5) {
        return  textSize.height+220;
    }else {
        return  textSize.height;
    }
    
    
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}
@end











